Skip to content

Conversation

@otakenz
Copy link

@otakenz otakenz commented Nov 1, 2025

PR Description

Fixes: #4997

This PR fixes bug mentioned in #4997 except the bug on interactive-rebase "i".
I have yet to figure out a way to get common ancestor to quickly obtains all the commits from the feature branch starting from the common ancestor.
Otherwise, the current approach shown below will still cause issue when git.log.showWholeGraph=true.

func (self *LocalCommitsController) findCommitForQuickStartInteractiveRebase(selectedCommits []*models.Commit, endIdx int) (*models.Commit, error) {
	commit, index, ok := lo.FindIndexOf(self.c.Model().Commits, func(c *models.Commit) bool {
		// Causes bug issues#4997 when git.log.showWholeGraph=true
		return c.IsMerge() || c.Status == models.StatusMerged
	})

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Copilot AI review requested due to automatic review settings November 1, 2025 10:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the interactive rebase functionality to properly calculate and pass the parent commit index for various rebase operations. The key improvement is the addition of a new GetParentCommit helper method that finds the actual parent commit by traversing the commit graph, rather than relying on simple index arithmetic. The confirmation messages are also updated to clarify that operations squash/fixup into "the parent commit below" instead of just "the commit below".

  • Added GetParentCommit helper method to find actual parent commits in the commit list
  • Updated all rebase operations to calculate and pass the correct parent index
  • Clarified user-facing messages to specify "parent commit below"

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/gui/controllers/helpers/commits_helper.go Implements new GetParentCommit helper method to find parent commits by traversing commit history
pkg/gui/controllers/local_commits_controller.go Updates all rebase operations to calculate parent index using the new helper and passes it to git commands
pkg/gui/controllers/custom_patch_options_menu_action.go Updates patch operations to calculate and pass parent index
pkg/gui/controllers/commits_files_controller.go Updates file discard operation to calculate and pass parent index
pkg/commands/git_commands/rebase.go Updates rebase command methods to accept and use parent index parameter
pkg/commands/git_commands/patch.go Updates patch command methods to accept and use parent index parameter
pkg/commands/git_commands/rebase_test.go Adds parent index parameter to test cases
pkg/i18n/english.go Updates confirmation messages to clarify "parent commit below"
pkg/i18n/translations/ko.json Updates Korean translations to match English message changes
pkg/integration/tests/interactive_rebase/*.go Updates test expectations to match new confirmation messages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…holeGraph=true

- Able to accurately select the parent commit now, preventing incorrect
operations on merge commits and complex histories.
- Updated method signatures to accept a parent commit index for precise
targeting.
- Improved english confirmation prompts and translations to clarify
actions affect the parent commit below.

- Fixed: squash "s", drop "d", reword "r/R", discard "d",
edit/interactive-rebase "e", fixup "f", amend "a/A, patch "Ctrl-P"
- Not yet fixed: interative-rebase "i"

fix: GetParentCommit edge cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lazygit Rebase/Fixup/Reword/Squash onto wrong commit (sibling branch) when git.log.showWholeGraph=true

1 participant